package com.framework.sec.bs.impl;

import com.framework.bas.bs.IPlmBasBS;
import com.framework.bas.cache.ICache;
import com.framework.bas.param.QueryParam;
import com.framework.org.vo.BasOrgUser;
import com.framework.sec.bs.IPlmSecBS;
import com.framework.sec.util.PlmSecConstant;

public class PlmSecBSImpl implements IPlmSecBS {
	
	private IPlmBasBS plmBasBS;
	
	/**
	 * 缓存系统参数表
	 */
	private ICache cacheSecMenu;

	public IPlmBasBS getPlmBasBS() {
		return plmBasBS;
	}

	public void setPlmBasBS(IPlmBasBS plmBasBS) {
		this.plmBasBS = plmBasBS;
	}

	public ICache getCacheSecMenu() {
		return cacheSecMenu;
	}

	public void setCacheSecMenu(ICache cacheSecMenu) {
		this.cacheSecMenu = cacheSecMenu;
	}
	
	public void doInit(){
		// 1. 缓存所有菜单信息，key为id，value为PlmSecMenuVO数组
		doCacheAllMenuRights();
	}
	
	protected void doCacheAllMenuRights() {
//		cacheSecMenu.doInit();
	}
	
	public BasOrgUser queryUserInfo(String userCode){
		String queryHql = "SELECT A FROM BasOrgUser A WHERE A.loginId=?";
		String params[] = new String[]{userCode};
		QueryParam qp = QueryParam.getInstance(queryHql, params);
		return (BasOrgUser)(this.getPlmBasBS().queryOne(qp));
	}
	
	public String constructMenuCode() {
		//调用主键
		int exist_menu_code = countUpMenuCode();
		String short_menu_code = String.valueOf(exist_menu_code + 1);
		StringBuilder menu_code = new StringBuilder(4);
		for(int i = 0;i < PlmSecConstant.INIT_MENU_KEY_LENGTH - short_menu_code.length();i++) {
			menu_code.append(0);
		}
		menu_code.append(short_menu_code);
		return menu_code.toString();
		
	}
	
	private int countUpMenuCode(){
		QueryParam qp = QueryParam.getInstance2(PlmSecConstant.SQLID_SEC_PARENT_MENU_SIZE, null);
		return getPlmBasBS().querySize(qp);
	}
	private int countRowOrder(){
		QueryParam qp = QueryParam.getInstance2(PlmSecConstant.SQLID_SEC_ROW_ORDER_SIZE, null);
		return getPlmBasBS().querySize(qp);
	}


}
